<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="css/font-awesome.css">
    <link rel="stylesheet" href="css/bootstrap.css">
    <script src="js/jquery-3.4.1.min.js"></script>
    <title>上传菜谱</title>

    <style>
        * {
            margin: 0;
            padding: 0;
        }

        a {
            text-decoration: none
        }

        html,
        body {
            height: 100%;
        }

        /* 侧边导航栏 */
        .menu-wrap {

            position: fixed;
            left: 0;
            top: 0;
            bottom: 0;
            width: 55px;
            background-color: #f5f5f5;
            box-shadow: 1px 0 15px rgba(0, 0, 0, 0.07);
            overflow: hidden;
            z-index: 15;
        }

        .menu-wrap:hover {
            width: 250px;
        }

        .menu {
            position: absolute;
            left: 0;
            top: 80px;
            bottom: 80px;
            width: 250px;
            overflow-y: auto;
            margin-top: 80px;
        }

        .menu li {
            height: 42px;
            line-height: 42px;

        }

        .menu li:hover {
            background-color: rgb(160, 190, 117);
        }

        .menu li:hover a {
            color: #fff;
        }

        .menu a {
            display: block;
            columns: #8a8a8a;
            border-top: 1px solid #e9e9e9;
        }

        .menu i {
            display: inline-block;
            width: 55px;
            text-align: center;
            font-size: 18px;
        }

        .menu span {
            font-size: 14px;
        }

        /* 侧边头像 */
        #headPic {
            width: 80px;
            height: 80px;
            border: 1px solid #ccc;
            border-radius: 75px;
            margin-left: 80px;
            /* margin:20px auto; */
            position: relative;
            overflow: hidden;
            top: 50px;
        }

        #headPicimg {
            width: 80px;
            height: 80px;
        }

        #headPic:hover #mask {
            display: block;
        }

        #mask {
            width: 150px;
            height: 150px;
            background-color: rgba(0, 0, 0, 0.5);
            position: absolute;
            left: 0;
            top: 0;
            display: none;
        }

        #innerImg {
            position: absolute;
            left: 25%;
            top: 25%;
            transform: translate(-50%, -50%);
            /*适用于不清楚自己的尺寸情况*/
        }

        /* 上传菜谱 */
        .sharemenu {
            width: 80%;
            min-width: 800px;
            /* border:1px solid red; */
            height: 1000px;
            position: relative;
            left: 130px;
            margin: 0 auto;
        }

        .smtitle {
            margin-top: 20px;
            height: 70px;
            /* background-color: yellow; */
        }

        .smtitle span {
            font-size: 17px;
            color: #888;
            display: block;
            height: 40px;
            line-height: 40px;
            /* background-color: red; */
            /* border-bottom: 1px solid #ccc; */
        }

        .smtitle p {
            padding-top: 2px;
            font-size: 12px;
            color: grey;
        }

        /* 添加菜谱名称 */
        .addtitle span {
            font-weight: bold;
        }

        /* form{
            width: 100%;
        } */
        [type="text"] {
            margin-right: 20px;
        }

        /* 上传成品图 */
        .addimg {
            margin-top: 20px;
            width: 100%;
            height: 400px;
            /* border:1px solid green; */
        }

        .addimg span {
            font-weight: bold;
        }

        .addimgword {
            margin-top: 5px;
        }

        .addimgword img {
            width: 250px;
            height: 300px;
            float: left;

        }

        .addimgword textarea {
            float: left;
        }

        .addimgword input {
            display: none;
        }

        /* 步骤 */
        .step {
            width: 100%;
            height: 900px;
            /* border:1px solid blue; */
        }

        .step table tr {
            padding: 50px;
        }

        .steptitle span {
            font-weight: bold;
        }

        .stepnumber {
            height: 180px;
            width: 100px;
            font-size: 60px;
            color: grey;
            font-family: Arial, Helvetica, sans-serif;
            font-weight: bold;
            display: inline-block;
            vertical-align: top;
            line-height: 180px;
        }

        .step table tr td img {
            height: 180px;
            width: 180px
        }

        /* 图片files隐藏 */
        .step table tr input {
            display: none;
        }

        /* 提交按钮 */
        button {
            width: 100px;
            height: 40px;
            position: relative;
            left: 300px;
            top: 30px;
        }
    </style>
    <script>
        var stepnum=1;
        var num = 1;
        window.onload = function () {
            //头像
            document.querySelector('#headPic').onclick = function () {
                document.querySelector('#headPic input').click()     //模拟表单元素被单击
            }

            // 点击出现成品图片(1)
            document.querySelector(".addimgword img").onclick = function () {
                document.querySelector('.addimgword input').click()
            }
            // 点击出现步骤图片(1)
            // document.querySelector("tr img").onclick = function () {
            //     document.querySelector('tr input').click()
            // }

        }

        // 头像
        function changeHeadPic() {
            //1.获取图片文件
            var fileHead = document.querySelector('#headPic input').files[0]
            //2.文件读取图片
            var fread = new FileReader()
            fread.onload = function (e) {
                //3.把图片显示在页面中
                document.querySelector('#headPic>img').src = e.target.result
            }
            fread.readAsDataURL(fileHead)
        }
        // 点击出现成品图片(2)
        function changeimg() {
            var fileimg = document.querySelector(".addimgword input");
            var fread = new FileReader();
            fread.onload = function (e) {
                document.querySelector(".addimgword img").src = e.target.result;
            }
            fread.readAsDataURL(fileimg.files[0])
        }
        //步骤step
        $(function () {
            $('table').on('click', '.img', function () {
                $(this).parent().find('input').click()
            })
        })
        $(function () {
            $('table').on('change','.stepimg',function () {
                var fread = new FileReader()
                var img = $(this).parent().find('img')
                fread.onload = function (e) {
                    img.attr('src',e.target.result)
                }
                fread.readAsDataURL(this.files[0])
            })
        })

        $(function () {
            $('.add').click(function () {
                stepnum++;
                var newNode = '<tr><td><div class="stepnumber">'+stepnum+'</div></td><td><img id="img" class="img" src="images/sharemenustep.PNG" alt=""><input class="stepimg" type="file" form="imformation"></td><td><textarea name="" id="" cols="65" rows="9" form="imformation" placeholder="请填写制作步骤与技巧"></textarea></td></tr>'
                $('table').append(newNode);
            })
            $('.dele').click(function () {
                stepnum--;
                if (confirm('确定要删除该记录吗?')) {
                    $('table tr:last').remove();
                }
            })
        })
        // 头像
        function myUploadFile() {
            var myImg = document.querySelector('#touxiang img')
            var txinput = document.querySelector('#touxiang input')
            var fread = new FileReader()
            fread.onload = function (e) {
                myImg.src = e.target.result
            }
            fread.readAsDataURL(txinput.files[0])
        }
    </script>
</head>

<body>
    <div>
        <!-- 侧边导航栏 -->
        <nav class="menu-wrap">
            <div id="headPic">
                <img id="headPicimg" src="images/icon_shangjie.gif" alt="">
                <div id="mask">
                    <img id="innerImg"
                        src=""
                        alt="">
                </div>
                <form action="#">
                    <input type="file" name="" id="" accept="image/jpg" onchange="changeHeadPic()" style="display:none">
                </form>
            </div>
            <div class="menu">
                <ul>

                    <li>
                        <a href="shouye.html">
                            <i class="fa fa-home fa-lg"></i>
                            <span class="nav-text">首页</span>
                        </a>
                    </li>
                    <li>
                        <a href="edit.html">
                            <i class="fa fa-bullhorn fa-lg"></i>
                            <span class="nav-text">编辑资料</span>
                        </a>
                    </li>
                    <li>
                        <a href="sharemenu.html">
                            <i class="fa fa-user fa-lg"></i>
                            <span class="nav-text">上传菜谱</span>
                        </a>
                    </li>
                    <li>
                        <a href="personal.html">
                            <i class="fa fa-envelope-o fa-lg"></i>
                            <span class="nav-text">已发布的内容</span>
                        </a>
                    </li>
                    <li>
                        <a href="shoucang.html">
                            <i class="fa fa-heart-o fa-lg"></i>
                            <span class="nav-text">收藏</span>
                        </a>
                    </li>
                    <li>
                        <a href="integral.html">
                            <i class="fa fa-shopping-bag fa-lg"></i>
                            <span class="nav-text">积分兑换</span>
                        </a>
                    </li>
                </ul>
            </div>
        </nav>
        <!-- 上传菜谱 -->
        <div class="sharemenu">
            <div class="smtitle">
                <span>发布菜谱</span>
                <p>分享点滴生活，让枯燥的厨房生活变得丰富有趣！</p>
            </div>
            <div class="addtitle">
                <i class="fa fa-bars text-success" aria-hidden="true"></i>
                <span>菜谱名称</span>
                <form action="#" id="imformation"></form>
                <input type="text" size="50" placeholder="请输入菜谱名称" required form="imformation">


            </div>
            <div class="addimg">
                <i class="fa fa-camera text-success" aria-hidden="true"></i>
                <span>上传成品图</span>
                <div class="addimgword">
                    <img src="images/sharemenuimg1.PNG" alt="">
                    <input type="file" onchange="changeimg()" form="imformation">
                    <textarea name="" id="" cols="70" rows="15" form="imformation" placeholder="分享菜谱背后的事故吧"></textarea>
                </div>
            </div>
            <div class="step">
                <div class="steptitle"><span>做法步骤</span></div>
                <table>
                    <tr>
                        <td>
                            <div class="stepnumber">1</div>
                        </td>
                        <td><img class='img' src="images/sharemenustep.PNG" alt="">
                            <input class="stepimg" type="file" form="imformation">
                        </td>
                        <td> <textarea name="" id="" cols="65" rows="9" form="imformation"
                                placeholder="请填写制作步骤与技巧"></textarea></td>
                    </tr>
                </table>
                <div>
                    <a href="####" class="add">添加一行</a>
                    <a href="####" class="dele">删除一行</a>

                </div>
                <button class="btn btn-success" form="imformation">提交</button>
            </div>

        </div>
    </div>
</body>

</html>